<template>
	<view class="login-page">
		<u-navbar title="" :placeholder="true" bgColor="rgba(0,0,0,0.0)" :autoBack="true">
		</u-navbar> 
		<view class="head-top">
			{{title}}
		</view>
		<view class="content">
			<view class="title">
				账号/手机号
			</view>
			<view class="entry">
				<u--input placeholder="请输入手机号" border="none" v-model="tell"></u--input>
			</view>
			<view class="title">
				新密码
			</view>
			<view class="entry">
				<u-input :type="entry_type" placeholder="请输入密码" border="none" v-model="password">
					<template slot="suffix">
						<u-icon v-if="status == true" name="eye" color="#8B8DA0" size="24"
							@click="cutType"></u-icon>
						<u-icon v-else name="eye-off" color="#8B8DA0" size="24" @click="cutType"></u-icon>
					</template>
				</u-input>
			</view>
			<view class="title">
				验证码
			</view>
			<view class="entry">
				<u-input type="Number" placeholder="请输入验证码" border="none" v-model="code">
					<template slot="suffix">
						<u-code ref="uCode" @change="codeChange" startText="发送" seconds="60" changeText="X秒重新获取"></u-code>
						<u-button  shape="circle" @tap="getCode" :text="tips" type="success" size="mini" color="#5755F2"></u-button>
					</template>
				</u-input>
			</view>
			<view class="hand-btn"  @click="goquer">
				<image src="https://m.lqvvvv.com/assets/static/login/hand.png" mode=""></image>
			</view>	
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tell: '',
				password: '',
				entry_type: 'password',
				status: false,
				tips: '',
				code: '',
				title:''
			}
		},
		onLoad(e) {
			if(e.type == '1'){
				this.title = '修改密码'
			}else{
				this.title = '忘记密码'
			}
		},
		methods: {
			goquer(){
				if (this.tell == '') {
					uni.showToast({
						title: '手机号不能为空！',
						icon: 'none'
					})
					return
				}
				if (this.code == '') {
					uni.showToast({
						title: '验证码不能为空！',
						icon: 'none'
					})
					return
				}
				if (this.password == '') {
					uni.showToast({
						title: '密码不能为空！',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					mask:true
				})
				let params = {
					mobile: this.tell,
					newpassword: this.password,
					captcha:this.code,
				}
				this.$Request({
					method: 'POST',
					url: '/api/user/resetpwd',
					data: params,
					ismsg: true,
				}).then(res => {
					console.log(res)
					uni.hideLoading();
					if (res.code == 1) {
						uni.showToast({
							title:"修改成功！",
							icon:'none'
						})
					}
				})
			},
			cutType() {
				if (this.status == false) {
					this.entry_type = 'text'
					this.status = true
				} else {
					this.entry_type = 'password'
					this.status = false
				}
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if(this.tell == ''){
					uni.showToast({
						title:'手机号不能为空！',
						icon:'none'
					})
					return
				}
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					let params = {
						mobile: this.tell,
						event: 'changepwd'
					}
					this.$Request({
						method: 'POST',
						url: '/api/sms/send',
						data: params,
						ismsg: true,
					}).then(res => {
						console.log(res)
						if (res.code == 1) {
							uni.hideLoading();
							// 这里此提示会被this.start()方法中的提示覆盖
							uni.$u.toast('验证码已发送');
							// 通知验证码组件内部开始倒计时
							this.$refs.uCode.start();
						}
					})
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login-page {
		height: 100vh;
		background-image: url('https://m.lqvvvv.com/assets/static/index/home-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 900rpx;
		padding: 0 30rpx;
		background-color: #F7F8FC;

		.head-top {
			padding: 30rpx;
			color: #19394A;
			font-weight: bold;
			font-size: 64rpx;
		}

		.content {
			background-image: url('https://m.lqvvvv.com/assets/static/login/login-bg.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			margin-top: 60rpx;
			padding: 50rpx;

			.title {
				margin-bottom: 30rpx;
				color: #2E314A;
				font-size: 32rpx;
				font-weight: bold;
			}

			.entry {
				background-color: #F9F9F9;
				padding: 20rpx 30rpx;
				border-radius: 20rpx;
				margin-bottom: 30rpx;
			}
			.hand-btn {
				margin-top: 100rpx;
				padding: 0 30rpx;
				image {
					width: 100%;
					height: 110rpx;
				}
			}
		}
	}
</style>